//
//  OpinionViewController.m
//  PaiLeXiongProject
//
//  Created by 小獾科技 on 2017/9/8.
//  Copyright © 2017年 小獾科技. All rights reserved.
//

#import "OpinionViewController.h"

@interface OpinionViewController ()<UITextViewDelegate>
@property (nonatomic, strong) UILabel *placeLabel;
@property (nonatomic, strong) UITextView *textView;
@end

@implementation OpinionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addBackItem];
    self.title = @"意见反馈";
    _textView = [UITextView new];
    _textView.layer.borderColor = ColorFrom16(0xD0D0D0).CGColor;
    _textView.layer.borderWidth = 1;
    _textView.layer.backgroundColor = ColorWhite.CGColor;
    _textView.layer.cornerRadius = 4;
    _textView.font = PFRFONT(18);
    _textView.delegate = self;
    _textView.autocorrectionType = UITextAutocorrectionTypeNo;
    [self.view addSubview:_textView];
    [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(8);
        make.left.equalTo(self.view).offset(27);
        make.right.equalTo(self.view).offset(-80);
        make.height.equalTo(@114);
    }];
    
    
    _placeLabel = [UILabel new];
    _placeLabel.text = @"我们能帮助您什么呢?";
    _placeLabel.textColor = ColorFrom16(0x949494);
    _placeLabel.font = PFRFONT(18);
    [_textView addSubview:_placeLabel];
    [_placeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_textView).offset(7);
        make.left.equalTo(_textView).offset(10);
        make.width.greaterThanOrEqualTo(@150);
        make.height.equalTo(@40);
    }];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"提交" forState:0];
    [button setTitleColor:ColorFrom16(0x616161) forState:0];
    button.titleLabel.font = PFRFONT(18);
    [button addTarget:self action:@selector(actionBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(52 );
        make.right.equalTo(self.view).offset(-20);
        make.width.equalTo(@40);
        make.height.equalTo(@25);
    }];
    
    UIView *line = [UIView new];
    line.backgroundColor = COLOR_BACKGROUND;
    [self.view addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_textView.mas_bottom).offset(35);
        make.left.and.right.equalTo(self.view);
        make.height.equalTo(@1);
    }];
    
    UILabel *titleLabel = [UILabel new];
    titleLabel.text = @"我们表现的怎么样呢?";
    titleLabel.textColor = ColorFrom16(0x333333);
    titleLabel.font = PFMFONT(22);
    [self.view addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(line.mas_bottom).offset(20);
        make.width.equalTo(@232);
        make.height.equalTo(@30);
        make.centerX.equalTo(self.view.mas_centerX);
    }];
    
    UILabel *text = [UILabel new];
    text.text = @"派乐熊和家长一同悉心呵护孩子的健康成长，是每一个家长的小伙伴，陪伴孩子们成长每一步。我们想了解您喜欢派乐熊应用哪些方面，以及您认为我们哪些方面能够做的更好。";
    text.textColor = ColorFrom16(0x616161);
    text.font = PFRFONT(18);
    text.numberOfLines = 0;
    [self.view addSubview:text];
    [text mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(25);
        make.left.equalTo(self.view).offset(25);
        make.right.equalTo(self.view).offset(-25);
        make.height.greaterThanOrEqualTo(@125);
    }];
}

- (void)actionBtn:(UIButton *)sender
{
    if([GW_Tool isEmptyString:_textView.text])
    {
        MESSAGE_TOAST(@"请输入反馈内容");
        return;
    }
    [NetWork sendPostRequestURL:[NSString stringWithFormat:@"%@/opinion/pushOpinion", GW_Domain] parameters:@{@"content":_textView.text} completionBlockWithSuccess:^(NSDictionary *resultDict) {
        NSLog(@"%@", resultDict);
        if([[NSString stringWithFormat:@"%@", resultDict[@"code"]] isEqualToString:@"0"])
        {
            MESSAGE_TOAST(@"提交成功");
            [self.navigationController popViewControllerAnimated:YES];
        }
    } andFailure:^(NSError *error, NSString *errorMsg) {
        NSLog(@"%@", errorMsg);
    }];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
{
    _placeLabel.hidden = YES;
    return YES;
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    if(textView.text.length == 0)
    {
        _placeLabel.hidden = NO;
    }
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
